# -*- coding: utf-8 -*-
# @Author : HaleShi
# @Time : 2023-07-04
# @File : 1_get_imgCode.py

import requests
import base64


def fetch_image_code():
    res = requests.get(
        url="https://newappuser.jiuxian.com/messages/graphCode.htm",
        params={
            "appKey": "713d4b0d-6a15-3436-a63e-13250682ba3f",
            "appVersion": "9.0.30",
            "areaId": "500",
            "channelCode": "0",
            "cpsId": "xiaomi",
            "deviceIdentify": "713d4b0d-6a15-3436-a63e-13250682ba3f",
            "deviceType": "ANDROID",
            "deviceTypeExtra": "0",
            "equipmentType": "Pixel 2 XL",
            "mobile": "18378353331",
            "netEnv": "wifi",
            "pushToken": "Akuwre13Fge-QlvEvjef4neaohHC8S48koHzVyRtdH8x",
            "screenReslolution": "1440x2712",
            "supportWebp": "1",
            "sysVersion": "10",
            "type": "4"
        },
        headers={
            "secure": "false",
            "Accept-Encoding": "gzip",
            'user-agent': "okhttp/3.14.9",
            'Host': "newappuser.jiuxian.com",
            'Connection': "keep-alive"
        },
    )
    print(res.json())
    image_str = res.json()['result']["imgCode"]

    image_bytes = base64.b64decode(image_str)

    with open("v2.png", mode='wb') as f:
        f.write(image_bytes)


def run():
    fetch_image_code()


if __name__ == '__main__':
    run()
